﻿#include "FITKAbaLoadManager.h"
#include "FITKAbaAbstractLoad.h"
#include "FITKAbaAbstractStep.h"

namespace Interface {

void FITKAbaLoadManager::deleteStepLoad(int stepId)
{
    int count = this->getDataCount();
    QList<FITKAbaAbstractLoad*> loadsToDelete{};
    for (int i = 0 ; i< count; ++i)
    {
        FITKAbstractLoad* load = this->getDataByIndex(i);
        FITKAbaAbstractLoad* abaLoad = dynamic_cast<FITKAbaAbstractLoad*>(load);
        if (abaLoad == nullptr)
            continue;
        if (abaLoad->getCreatedStep() == stepId)
            loadsToDelete.append(abaLoad);
    }
    for (FITKAbaAbstractLoad* l : loadsToDelete)
    {
        this->removeDataObj(l);
    }
}

void FITKAbaLoadManager::replaceStep(int oldStep, int newStep)
{
    int count = this->getDataCount();
    for (int i = 0; i < count; ++i)
    {
        FITKAbstractLoad* bdata = this->getDataByIndex(i);
        FITKAbaAbstractLoad* data = dynamic_cast<FITKAbaAbstractLoad*>(bdata);
        if (data == nullptr)
            continue;
        if (data->getCreatedStep() != oldStep)
            continue;
        data->setCreatedStep(newStep);
        if (!data->isValidInCreatedStep())
            data->setActiveState(false);
    }
}

}
